package com.olddriver.crm.service.impl;

import com.olddriver.crm.domain.ClientFollow;
import com.olddriver.crm.domain.Employee;
import com.olddriver.crm.mapper.ClientFollowMapper;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.ClientFollowQueryObject;
import com.olddriver.crm.service.IClientFollowService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ClientFollowServiceImpl implements IClientFollowService {

    @Autowired
    private ClientFollowMapper clientFollowMapper;

    public int save(ClientFollow clientFollow){
        //设置录入人
        Employee inputUser = (Employee) SecurityUtils.getSubject().getPrincipal();
        clientFollow.setInputUser(inputUser);
        return clientFollowMapper.save(clientFollow);
    }

    public void update(ClientFollow clientFollow) {
        clientFollowMapper.update(clientFollow);
    }

    public void delete(Long id) {
        clientFollowMapper.delete(id);
    }

    public ClientFollow get(Long id) {
        return clientFollowMapper.get(id);
    }

    public List<ClientFollow> list() {
        return clientFollowMapper.list();
    }

    public PageResult query(ClientFollowQueryObject qo) {
        int total = clientFollowMapper.queryTotal(qo);
        if (total == 0) {
            return new PageResult(total, Collections.emptyList());
        }
        return new PageResult(total, clientFollowMapper.queryRows(qo));
    }

    public void sign(Long id, Integer result_id) {
        clientFollowMapper.sign(id,result_id);
    }
}
